package com.oplink.webems.common.snmp.entity;

import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;

public class TrapEvent {
	private static LinkedBlockingQueue<Map<String,String>> link = new LinkedBlockingQueue<Map<String, String>>(100);
	private static TrapEvent te;
	private TrapEvent(){
		
	}
	
	public static TrapEvent getInstance(){
		if(te == null){
			te = new TrapEvent();
		}
		return te;
	}
	
	public synchronized Map<String,String> take(){
		if(link.peek() == null){
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		try {
			Map<String,String> v = link.take();
			return v;
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public synchronized void put(Map<String,String> v) {
		try {
			boolean empty = link.peek()==null;
			link.put(v);
			if(empty){
				notify();
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
